package com.cheetah.cloud2020.web;

import com.cheetah.cloud2020.bean.ResponseResult;
import com.cheetah.cloud2020.bean.ResultCode;
import com.cheetah.cloud2020.entity.SystemAdmin;
import com.cheetah.cloud2020.service.SystemAdminService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/auth")
public class AdminAuthController {

    @Autowired
    @Lazy
    private SystemAdminService systemAdminService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult login(@RequestBody SystemAdmin query) {
        String username = query.getUsername();
        String password = query.getPassword();
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            return ResponseResult.fail(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMessage());
        }
        return ResponseResult.ok(this.systemAdminService.login(username, password));
    }

    @RequestMapping("/info")
    @ResponseBody
    public ResponseResult info() {
        return ResponseResult.ok("简单的返回");
    }
}
